package DataStructures.sort;

/**
 * @author ：ALi
 * @date ：Created in 2021/11/7 17:27
 * @description：冒泡排序
 * @modified By：
 * @version: $
 */
public class BubbleSorting {
    public static void main(String[] args) {
        int[] array = {1,3,2,5,4,7,6,9,8};
        sort(array);
        for (int i = 0;i<array.length;i++){
            System.out.print(array[i]+" ");
        }

    }

    public static void sort(int[] array) {
        int temp = 0;
        boolean flag = false;
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - 1 - i; j++) {
                if (array[j] > array[j + 1]) {
                    flag = true;
                    temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }

            }
            if (!flag) {
                break;
            } else {
                flag = false;
            }
        }
    }
}